package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsKeywordMapper;
import com.qf.pojo.DtsKeyword;
import com.qf.service.DtsKeywordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author 邢式瑞
 * @version 1.0
 * @project E-commercebackGroundManagementSystem
 * @date 2022/9/24 13:42
 */
@Service
public class DtsKeywordServiceImpl implements DtsKeywordService {
    @Autowired
    private DtsKeywordMapper dtsKeywordMapper;
    @Override
    public Page<DtsKeyword> selectPage(Integer page, Integer limit, String sort, String order, String keyword, String url) {
        Page<DtsKeyword> dtsKeywordPage = new Page<>(page, limit);
        QueryWrapper<DtsKeyword> dtsKeywordQueryWrapper = new QueryWrapper<>();
        dtsKeywordQueryWrapper.orderBy(!StringUtils.isEmpty(sort),"asc".equalsIgnoreCase(order),sort).like(!StringUtils.isEmpty(keyword),"keyword",keyword).eq(!StringUtils.isEmpty(keyword),"url",url).eq("deleted",false);
        return dtsKeywordMapper.selectPage(dtsKeywordPage,dtsKeywordQueryWrapper);
    }

    @Override
    public void insertKey(DtsKeyword dtsKeyword) {
        dtsKeywordMapper.insert(dtsKeyword);
    }

    @Override
    public void updateKey(DtsKeyword dtsKeyword) {
dtsKeywordMapper.updateById(dtsKeyword);
    }

    @Override
    public void deleteKey(DtsKeyword dtsKeyword) {
  dtsKeywordMapper.updateById(dtsKeyword);
    }
}
